﻿Imports System
Imports System.Linq
Imports System.Data
Imports System.Web
Imports Equipment.DataAccess

<Serializable()> _
Public Class AssetWrapper

#Region "Properties"
    Public AssetID As Integer
    Public AssetName As String
    Public SerialNo As String
    Public ModelNo As String
    Public AssetType As String
    Public AssetTypeID As Integer
    Public SiteDepartment As String
    Public Status As String
    Public BarcodeID As String
#End Region


    Public Shared Function ConvertToWrapperList(ByVal equipmentSource As IEnumerable(Of Equipment.DataAccess.Asset)) As List(Of AssetWrapper)
        Dim wrapperList As New List(Of AssetWrapper)

        For Each e In equipmentSource
            Dim w As New AssetWrapper
            w.AssetID = e.AssetID
            w.AssetName = e.AssetName
            w.ModelNo = e.ModelNo
            w.SerialNo = e.SerialNo
            w.AssetTypeID = e.AssetTypeID
            w.BarcodeID = e.BarcodeID
            If e.AssetType Is Nothing Then
                w.AssetType = String.Empty
            Else
                w.AssetType = e.AssetType.Description
            End If
            If e.SiteDepartment Is Nothing Then
                w.SiteDepartment = String.Empty
            Else
                w.SiteDepartment = e.SiteDepartment.Description
            End If
            wrapperList.Add(w)
        Next

        Return wrapperList
    End Function

    Public Shared Function GetFrom(ByVal a As Equipment.DataAccess.Asset) As AssetWrapper
        Dim wrapperList As New List(Of AssetWrapper)

        Dim w As New AssetWrapper
        w.AssetID = a.AssetID
        w.AssetName = a.AssetName
        w.ModelNo = a.ModelNo
        w.SerialNo = a.SerialNo
        w.AssetTypeID = a.AssetTypeID
        w.BarcodeID = a.BarcodeID
        If a.AssetType Is Nothing Then
            w.AssetType = String.Empty
        Else
            w.AssetType = a.AssetType.Description
        End If
        If a.SiteDepartment Is Nothing Then
            w.SiteDepartment = String.Empty
        Else
            w.SiteDepartment = a.SiteDepartment.Description
        End If


        Return w
    End Function


End Class
